<template>
    <div class="template-list" v-loading="loading">
        <div>
          <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane :label="`浏览过`" name="first"></el-tab-pane>
            <el-tab-pane :label="`已收藏 ${counts && counts.collectNum || 0}`" name="second"></el-tab-pane>
            <el-tab-pane :label="`咨询过卖家或顾问 ${counts && counts.chatNum || 0}`" name="third"></el-tab-pane>
            <el-tab-pane :label="`有下单 ${counts && counts.orderNum || 0}`" name="fourth"></el-tab-pane>
          </el-tabs>
        </div>
        <div style="color: #837d7d; font-size: 14px">仅展示近30天的记录</div>
        <div class="table-box">
            <el-table :data="tableData" ref="table" border style="width: 100%">
                <el-table-column width="120" label="账号">
                  <template slot-scope="scope">
                    <div class="table-btn" @click="goQQDetails(scope.row)">QQ：<span>{{ scope.row.accountNo }}</span></div>
                      <div>{{ scope.row.serverName }}</div>
                      <div class="table-btn" @click="goUserDetail(scope.row.accountUserId)">号主：<span>{{ scope.row.accountUserId }}</span></div>
                  </template>
                </el-table-column>
                <el-table-column width="120" label="游戏">
                  <template slot-scope="scope">
                      <span>{{ scope.row.gameName }}</span>
                  </template>
                </el-table-column>
                <el-table-column width="120" label="估值">
                  <template slot-scope="scope">
                      <span>{{ scope.row.worth}}</span>
                  </template>
                </el-table-column>
                <el-table-column sortable width="120" label="售价">
                  <template slot-scope="scope">
                      <span>{{ scope.row.price}}</span>
                  </template>
                </el-table-column>
                <el-table-column width="200" label="描述">
                  <template slot-scope="scope">
                      <span>{{ scope.row.title}}</span>
                  </template>
                </el-table-column>
                <el-table-column width="120" label="浏览时间">
                  <template slot-scope="scope">
                      <span>{{ _formatDate(scope.row.createTime) || '-' }}</span>
                  </template>
                </el-table-column>
                <el-table-column width="120" label="是否收藏">
                  <template slot-scope="scope">
                      <span v-if="scope.row.isCollect" style="color: rgb(0, 186, 69);">是</span>
                      <span v-else>否</span>
                  </template>
                </el-table-column>
                <el-table-column width="120" label="是否咨询">
                  <template slot-scope="scope">
                      <span v-if="scope.row.isChat" style="color: rgb(0, 186, 69);">是</span>
                      <span v-else>否</span>
                  </template>
                </el-table-column>
                <el-table-column width="120" label="是否下单">
                  <template slot-scope="scope">
                      <span v-if="scope.row.isOrder" style="color: rgb(0, 186, 69);">是</span>
                      <span v-else>否</span>
                  </template>
                </el-table-column>
                <el-table-column label="账号状态">
                  <template slot-scope="scope">
                      <span v-if="scope.row.status === -2">已注销</span>
                      <span v-if="scope.row.status === -1">审核拒绝</span>
                      <span v-if="scope.row.status === 0">待提交</span>
                      <span v-if="scope.row.status === 1">待审核</span>
                      <span v-if="scope.row.status === 2">待上架</span>
                      <span v-if="scope.row.status === 3">已上架</span>
                      <span v-if="scope.row.status === 4">交易中</span>
                      <span v-if="scope.row.status === 5">已售出</span>
                      <span v-if="scope.row.status === 6">未知</span>
                  </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="tools">
          <el-pagination
              @size-change="sizeChange"
              @current-change="pageChange"
              :current-page="pageNum"
              :page-sizes="this._pageSizes"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
          </el-pagination>
        </div>
    </div>
</template>

<script>
import { formatDate } from '@/utils/utils'
export default {
    data () {
        return {
            tableData: [],
            pageNum: 1,
            pageSize: 30,
            total: 0,
            loading: false,
            activeName: 'first',
            statusChangeVal: null,
            userId: null,
            counts: {}
        }
    },
    created () {
        this.userId = this.$route.query.id
        this.getList(this.pageNum)
        this.getAdviseCount()
    },
    methods: {
        // 获取数目
        async getAdviseCount() {
            let res = await this.$http.get(`/user/adviseUserViewTapCount?userId=${this.userId}`, { 
            })
            if (res.code === '0') {
                this.counts = res.data
            } else {
                this.$message({
                    type: 'error',
                    message: '系统异常，请稍后再试'
                })
            }
        },
        // 点击QQ账号 跳转到相应的 租号账号详情
        goQQDetails (item) {
            let path = `/seller/accTradingDetail?dataId=${item.dataId}`
            const { href } = this.$router.resolve({
                path
            })
            window.open(href, '_blank')
        },
        // 查看用户详情
        goUserDetail (id) {
            const { href } = this.$router.resolve({
                path: '/dataReport/userInfo',
                query: {
                    id
                }
            })
            window.open(href, '_blank')
        },
        handleClick(tab, event) {
          let status = Number(tab.index)
          if (!status) {
            this.statusChangeVal = null
          }
          this.statusChangeVal = status
          this.getList(1)
        },
        // 获取列表
        async getList (pageNum) {
            if (this.loading) return
            this.pageNum = pageNum
            this.loading = true
            let params = {
                pageNum: pageNum,
                pageSize: 30,
                type: this.statusChangeVal,
                userId: this.userId
            }
            let res = await this.$http.get('/user/adviseUserView', {
                params
            })
            if (res.code === '0') {
                this.tableData = res.data.list
                this.total = res.data.totalRow
            } else {
                this.$message({
                    type: 'error',
                    message: '系统异常，请稍后再试'
                })
            }
            this.loading = false
        },
        _formatDate (timestamp) {
            return formatDate(timestamp, 'YYYY-MM-DD HH:MM')
        },
        // 页码切换
        sizeChange (val) {
            this.pageNum = 1
            this.pageSize = val
            this.getList(1)
        },
        // 页容切换
        pageChange (val) {
            this.pageNum = val
            this.getList(this.pageNum)
        }
    }
}
</script>

<style lang="scss" scoped>
    .template-list {
        .template-option-box {
            max-width: 800px;
        }

        .table-box {
            margin: 20px 0;
            .point {
                display:inline-block;
                width:10px;
                height:10px;
                border-radius: 50%;
                background-color:#67C23A;
                margin-right:3px;
            }
            .red-point {
                background-color: #F56C6C;
            }
        }

        .tools {
            padding-right: 20px;
            display: flex;
            justify-content: flex-end;
        }
    }
    .table-btn {
        cursor: pointer;
        color: #409EFF;
        font-size: 13px;
        font-weight: 500;
        &:hover {
            text-decoration: underline;
        }
    }
</style>
